package tiruvury.InterviewPrep.DataStructureTests;

import tiruvury.InterviewPrep.DataStructures.MyArrays;
import tiruvury.InterviewPrep.HelperClasses.MaxSumSubarray;

public class MyArrayTests
{
	public static void main(String[] args)
	{
		// Print the maximum sum subarray in an array, including the subarray
		// itself
		int[] arr = MyArrays.GenerateRandomIntArray(10, -5, 5, false);
		MaxSumSubarray maxSoFar = MyArrays.GetMaximumSumSubarray(arr);
		System.out.print("Max Sum Subarray: { ");
		for (int i = maxSoFar.lowIdx; i <= maxSoFar.highIdx; i++)
		{
			System.out.print(" " + arr[i] + ", ");
		}
		System.out.println(" } => " + maxSoFar.sum);

		// Print the minimum number in a rotated array
		System.out.println();
		arr = new int[]
		{ 3, 4, 5, 6, 7, 8, 1, 2 };
		System.out.println("Min Num in Rotated Array: " + MyArrays.FindMinInRotatedArray(arr));

		// Find Magic Index (index is same as the number)
		System.out.println();
		arr = MyArrays.GenerateRandomIntArray(10, 0, 9, false);
		System.out.println("Magic Index is: " + MyArrays.FindMagicIndex(arr, 0, arr.length - 1));

		// Return m random numbers in an array
		System.out.println();
		arr = MyArrays.GenerateRandomIntArray(40, 0, 100, false);
		MyArrays.ReturnMRandNums(arr, 7);
		System.out.println();

		// Print the index of a number in a in a rotated array
		System.out.println();
		arr = new int[]
		{ 18, 19, 20, 22, 1, 3, 5, 6, 8, 9, 12, 15 };
		int num = 12;
		System.out.println("Idx of " + num + " in Rotated Array: " + MyArrays.FindIdxInRotatedArray(arr, num));

		// Print pairs that sum to a value
		System.out.println();
		arr = MyArrays.GenerateRandomIntArray(10, 0, 30, false);
		MyArrays.PrintPairs(arr, 30);

		// Dutch National Flag Sort (REVIEW)
		System.out.println();
		arr = new int[]
		{ 1, 2, 1, 2, 0, 1, 0, 2, 1, 0 };
		System.out.print("After Dutch National Flag sort: { ");
		arr = MyArrays.DutchNationalFlagSort(arr);
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(" " + arr[i] + ", ");
		}
		System.out.println(" }");

		num = 6;
		MyArrays.PrintFibonacciNums(num);

		System.out.println();
		arr = new int[]
		{ 2, 8, 3, 2, 1, 2, 4, 7, 6, 9 };
		System.out.print("After MergeSort: { ");
		arr = MyArrays.MergeSort(arr, 0, arr.length - 1);
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(" " + arr[i] + ", ");
		}
		System.out.println(" }");

		System.out.println();
		arr = new int[]
		{ 2, 8, 3, 2, 1, 2, 4, 7, 6, 9 };
		int k = 1;
		System.out.print("Rotate array by " + k + ": { ");
		arr = MyArrays.rotateArrayByK(arr, k);
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(" " + arr[i] + ", ");
		}
		System.out.println(" }");
	}

}
